package com.huazi.eduservice.controller;

import com.huazi.commonutils.CommentResult;
import com.huazi.commonutils.CourseOrder;
import com.huazi.eduservice.service.EduChapterService;
import com.huazi.eduservice.service.EduCourseService;
import com.huazi.eduservice.vo.ChapterVideo;
import com.huazi.eduservice.vo.CourseWebVo;
import com.huazi.eduservice.vo.FrontCourseInfo;
import com.huazi.eduservice.vo.Options;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shkstart
 * @create 2021-03-29 18:26
 */
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {
    @Autowired
    EduCourseService courseService;
    @Autowired
    EduChapterService chapterService;
    //1.条件查询带分页查询课程
    @PostMapping("getCourseFrontList/{current}/{size}")
    public CommentResult getCourseFrontList(@PathVariable("current") Integer current, @PathVariable("size") Integer size, @RequestBody(required = false) FrontCourseInfo courseInfo){
        CommentResult courseFrontList = courseService.getCourseFrontList(current, size, courseInfo);
        return courseFrontList;
    }
    //2.课程详情列表信息
    @GetMapping("getFrontCourseInfo/{id}")
    public CommentResult getFrontCourseInfo(@PathVariable("id") String id ){
        // 根据课程id，获取课程详情信息
        // 1.获取讲师名称、所属课程、课程名称、所有章节和小节
        CourseWebVo courseWebVo =courseService.getBaseCourseInfo(id);
        //根据课程id获取所有章节和小节
        List<ChapterVideo> options = chapterService.getChapterVideo(id);

        return CommentResult.getOK().data("courseWebVo",courseWebVo).data("chapterVideoList",options);
    }
    //根据课程id获取课程信息（生成订单信息）
    @GetMapping("getCourseOrderInfo/{id}")
    public CourseOrder getCourseOrderInfo(@PathVariable String id){
        CourseWebVo courseWebVo = courseService.getBaseCourseInfo(id);
        CourseOrder courseOrder=new CourseOrder();
        BeanUtils.copyProperties(courseWebVo,courseOrder);
        return courseOrder;
    }

}
